package com.dycx.api.controller.manage.system;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.food.service.GoodsMainFoodService;
import com.dycx.food.service.OrderFoodService;
import com.dycx.system.dto.ConfigDTO;
import com.dycx.system.service.ConfigService;
import com.dycx.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/manage/system/config")
public class ConfigController {

    @Resource
    private ConfigService configService;

    private UserService userService;
    private GoodsMainFoodService goodsMainService;
    private OrderFoodService orderService;

    /**
     * 获取所有配置
     **/
    @GetMapping("/getAllConfig")
    public RestResponse<?> getAllConfig() {
        return RestResponse.success(configService.getAllConfig());
    }

    /**
     * 修改配置
     *
     * @return
     */
    @WriterLog(bizType = BizTypeEnum.SYS_CONFIG)
    @PostMapping("/updateConfig")
    public RestResponse<?> updateConfig(@RequestBody List<ConfigDTO> configDTOList) {
        configService.updateConfig(configDTOList);
        return RestResponse.success();
    }

    /**
     * 获取仪表数据
     **/
    @GetMapping("/getDashboardData")
    public RestResponse<?> getDashboardData() {
        int userCount = userService.count();
        int goodsCount = goodsMainService.count();
        int orderCount = orderService.count();

        Map<String, Integer> data = new HashMap<>();
        data.put("userCount", userCount);
        data.put("goodsCount", goodsCount);
        data.put("orderCount", orderCount);

        return RestResponse.success(data);
    }
}
